<template>
	<view class="order_details">
		<xbd-pages-content title="订单详情">
		<template #content>
			<view class="content">
				<view class="head">
					<view class="state">
						<text v-if="list.status === '0'">待派车</text>
						<text v-else-if="list.status === '1'">配送中</text>
						<text v-else-if="list.status === '2'">已完成</text>
						<text v-else-if="list.status === '3'">滞留</text>
						<text v-else-if="list.status === '4'">取消</text>
					</view>
					<view class="type">
						<view class="left">
							订单编号
						</view>
						<view class="right">
							{{id}}
						</view>
					</view>
					<view class="type">
						<view class="left">
							下单时间
						</view>
						<view class="right">
							{{ list.create_time | timeFormat('YYYY-MM-DD HH:mm:ss')}}
						</view>
					</view>
				</view>
				<view class="body">
					<view class="type">
						<view class="left">
							收货站点
						</view>
						<view class="right">
							{{list.receiving_site}}
						</view>
					</view>
					<view class="type">
						<view class="left">
							店铺
						</view>
						<view class="right">
							{{list.shop}}
						</view>
					</view>
					<view class="type">
						<view class="left">
							配送车辆
						</view>
						<view class="right">
							{{ list.car_name || '-'}}
						</view>
					</view>
					<view class="type">
						<view class="left">
							格口
						</view>
						<view class="right">
							{{ list.cabinet || '-'}}
						</view>
					</view>
					<view class="type">
						<view class="left">
							收货时间
						</view>
						<view class="right">
							{{ list.completion_time | timeFormat('YYYY-MM-DD HH:mm:ss') || '-'}}
						</view>
					</view>
					<view class="type">
						<view class="left">
							电话
						</view>
						<view class="right">
							{{ list.phone }}
						</view>
					</view>
					<view class="type">
						<view class="left">
							姓名
						</view>
						<view class="right">
							{{list.username}}
						</view>
					</view>
				</view>
				<!-- <view class="bottom">
					<view class="button" @click="add()" >查看车辆状态</view>
				</view> -->
				<view class="foot" v-if="msg === '1'">
					<view class="two">
						<view class="button" @click = "harvest">
							确认收货
						</view>
						<view class="button" @click ="stranded">
							确认滞留
						</view>
					</view>
				</view>
				<xbd-popup :isShow="showDialog1" @dialogConfirm="dialogConfirm" @dialogCancel="dialogCancel"
					content="确认收货？" cancelText="取消" confirmText="确定">
				</xbd-popup>
				<xbd-popup :isShow="showDialog2" @dialogConfirm="dialogConfirm_two" @dialogCancel="dialogCancel"
					content="确认滞留？" cancelText="取消" confirmText="确定"  >
				</xbd-popup>
				<xbd-popup :isShow="showDialog3" @dialogConfirm="dialogConfirm_three" @dialogCancel="dialogCancel"
					content="确认收货？" cancelText="取消" confirmText="确定"  >
				</xbd-popup>
				<view class="foot" v-if="msg === '2' && list.status === '3'">
					<view class="success">
						<view class="button" @click = "harvestSuccess">
							确认收货
						</view>
					</view>
				</view>
			</view>
			
		</template>
		</xbd-pages-content>
	</view>
</template>

<script>
	import { DeliveryOrder } from '@/api/index.js';
	export default {
		data() {
			return {
				msg:0,
				flag:true,
				showDialog1: false, //确认收获弹窗
				showDialog2: false, //确认滞留弹窗
				showDialog3: false, //确认完成弹窗
				id:'',
				info:{},
				list: {
				}, 
			};
		},
		methods: {
			add(){
				// 车辆状态
				uni.navigateTo({
					url:`./mapRoute?order`,
				})
			},
			
			// 
			harvest() {
				this.showDialog1 = true
				this.flag = true
			},
			harvestSuccess() {
				this.showDialog3 = true
				this.flag = true
			},
			stranded() {
				this.flag = true
				this.showDialog2 = true
			},
			// 关闭弹窗
			dialogConfirm() {
				if(this.flag){
				this.flag = false
				this.info={
					order_id: this.id, //订单ID
					box_index: this.list.cabinet, //格口编号
					type: "0" //完成类型-0完成 1滞留 2开箱取件
				}
				this.showDialog1 =false
				this.complete()
				}
			},
			dialogConfirm_two() {
				if(this.flag){
				this.flag = false
				this.info={
					order_id: this.id, //订单ID
					box_index: this.list.cabinet, //格口编号
					type: "1" //完成类型-0完成 1滞留 2开箱取件
				}
				this.showDialog2 =false
				this.complete()
				}
				
			},
			dialogConfirm_three() {
				if(this.flag){
				this.flag = false
				this.info={
					order_id: this.id, //订单ID
					box_index: this.list.cabinet, //格口编号
					type: "0" //完成类型-0完成 1滞留 2开箱取件
				}
				this.showDialog3 =false
				this.complete_success()
				}
				
			},
			dialogCancel(){
				this.showDialog1 =false
				this.showDialog2 = false
				this.showDialog3 = false
			},
			async complete(){
				try {
					this.$showLoading('加载中');
						const res = await DeliveryOrder.postCompleteOrder(this.info);
						uni.hideLoading();
						console.log(res,'res')
						if(res.success){
							uni.$emit('successOut',this.id)
							uni.showToast({
								title: '您的申请提交成功！',
								icon: 'none',
							})
							setTimeout(() => {
								uni.hideLoading();
								uni.navigateBack({
									delta: 1
								});
							}, 1500)
						}
						
					} catch (err) {
						uni.showToast({
							
							title: err.msg,
							icon: 'none',
						})
						setTimeout(() => {
							uni.hideLoading();
						}, 1500)
					}
				
			},
			async complete_success(){
				try {
					this.$showLoading('加载中');
						const res = await DeliveryOrder.postCompleteOrder(this.info);
						uni.hideLoading();
						if(res.success){
							uni.$emit('successChangeList',this.id)
							uni.showToast({
								title: '您的申请提交成功！',
								icon: 'none',
							})
							setTimeout(() => {
								uni.hideLoading();
								uni.navigateBack({
									delta: 1
								});
							}, 1500)
						}
						
					} catch (err) {
						uni.showToast({
							
							title: err.msg,
							icon: 'none',
						})
						setTimeout(() => {
							uni.hideLoading();
						}, 1500)
					}
				
			},
			async init(){
				try {
					this.$showLoading('加载中');
					const res = await DeliveryOrder.getOrderDetails(this.id);
					this.list = res.data
					uni.hideLoading();
				} catch (err) {
						uni.hideLoading();
					
				}
			},
		},
		computed: {
		},
		onLoad(res){
			this.id = res.id
			this.msg = res.msg
			this.init()
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .uni-easyinput__content-input{
		text-align: right;
	}
	::v-deep .is-input-border{
		border: none;
	}
	::v-deep .is-disabled {
		background-color: #FFFFFF !important;
	}
	.content{
		
		.head{
			padding: 0 40rpx 10rpx 40rpx;
			background-color: #FFFFFF;
			box-sizing: border-box;
			margin-bottom: 20rpx;
			.state{
				padding: 20rpx 0;
				border-bottom: 2rpx solid #E8E8E8;
				margin-bottom: 20rpx;
				color: #457AFF;
				font-size: 24rpx;
			}
		}
		.body{
			padding: 40rpx 40rpx 10rpx 40rpx;
			background-color: #FFFFFF;
			box-sizing: border-box;
		}
		.type {
			
			display: flex;
			justify-content: space-between;
			font-size: 28rpx;
			margin-bottom: 20rpx;
		
			.left {
				color: #BBC0C9;
			}
		
			.right {
				color: #394954 10000%;
			}
		}
		.bottom{
			display: flex;
			justify-content: center;
			margin-top: 80rpx;
			.button{
				width: 240rpx;
				height: 70rpx;
				line-height: 68rpx;
				text-align: center;
				border-radius: 8rpx;
				font-size: 28rpx;
				background-color: #FFFFFF;
				border: 2rpx solid #457AFF;
				color: #457AFF;
			}
		}
		.foot{
			width: 750rpx;
			position: fixed;
			bottom: 0;
			background-color: #FFFFFF;
			box-sizing: border-box;
			box-shadow: 0px -2px 6px 0px rgba(0, 0, 0, 0.1);
			.two{
				padding:0  160rpx;
				box-sizing: border-box;
				display: flex;
				justify-content: space-between;
				align-items: center;
				height: 100rpx;
				.button{
					width: 180rpx;
					height: 56rpx;
					line-height: 52rpx;
					text-align: center;
					box-sizing: border-box;
					border-radius: 8rpx;
					font-size: 24rpx;
					border: 2rpx solid #457AFF;
					color: #457AFF;
				}
			}
			.success{
				display: flex;
				justify-content: center;
				align-items: center;
				height: 100rpx;
				.button{
					width: 180rpx;
					height: 56rpx;
					line-height: 52rpx;
					text-align: center;
					box-sizing: border-box;
					border-radius: 8rpx;
					font-size: 24rpx;
					border: 2rpx solid #457AFF;
					color: #457AFF;
				}
			}
			
		}
	}

</style>
